package com.kdg.thread;

/**
 * @author kong
 */
public class ProrityDemo {

    public static class HighPriorityThread extends Thread {
        static int count = 0;

        @Override
        public void run() {
            while (true) {
                synchronized (ProrityDemo.class) {
                    count++;
                    if(count >10000000){
                        System.out.println("HighPriority is complete");
                        break;
                    }
                }
            }
        }
    }

    public static class LowPriorityThread extends Thread {
        static int count = 0;

        @Override
        public void run() {
            while (true) {
                synchronized (ProrityDemo.class) {
                    count++;
                    if(count >10000000){
                        System.out.println("LowPriority is complete");
                        break;
                    }
                }
            }
        }
    }

    /**
     * 高优先级的线程只是更大概率的获取资源
     * @param args
     */
    public static void main(String[] args) {
        Thread high = new HighPriorityThread();
        Thread low = new LowPriorityThread();
        low.setPriority(Thread.MAX_PRIORITY);
        high.setPriority(Thread.MIN_PRIORITY);
        high.start();
        low.start();
    }
}
